package com.hc.sp03.user.controller;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;
import sp01.pojo.User;
import sp01.service.UserService;
import sp01.util.JsonResult;

/**
 * @author He
 * @date 2021/8/30 15:44
 */
@RestController
@Slf4j
public class UserController {
    @Autowired
    private UserService userService;

    //获取用户
    @GetMapping("/{userId}")
    public JsonResult<User> getUser(@PathVariable Integer userId) {
        User user = userService.getUser(userId);
        return JsonResult.ok().msg("找到了").data(user);
    }


    //增加用户积分
    @GetMapping("/{userId}/score")
    public JsonResult<?> addScore(@PathVariable Integer userId, Integer score) {
        userService.addScore(userId, score);
        return JsonResult.ok().msg("增加用户积分成功" + score);
    }
}
